package canglang.monitor.cases.service.impl;

import canglang.monitor.cases.dao.CaseThreeDAO;
import canglang.monitor.cases.model.CaseThreeModel;
import canglang.monitor.cases.model.CaseLightModel;
import canglang.monitor.cases.service.CaseThreeMgr;
import canglang.monitor.cases.service.CaseLightMgr;
import canglang.monitor.cases.to.SearchThreeTO;
import canglang.monitor.cases.to.SearchTwoTO;
import canglang.monitor.core.base.pagination.PaginatedListHelper;
import canglang.monitor.core.base.util.DateUtil;

import java.util.List;
import java.util.Date;

public class CaseThreeMgrImpl implements CaseThreeMgr {

    private CaseThreeDAO caseThreeDAO;

    private CaseLightMgr caseLightMgr;

    public void setCaseLightMgr(CaseLightMgr caseLightMgr) {
        this.caseLightMgr = caseLightMgr;
    }

    public void setCaseThreeDAO(CaseThreeDAO caseThreeDAO) {
        this.caseThreeDAO = caseThreeDAO;
    }

    public CaseThreeModel addCaseThree(CaseThreeModel caseThreeModel) {
        int id = caseThreeDAO.addCaseThree(caseThreeModel);
        CaseLightModel caseLightModel = new CaseLightModel();
        caseLightModel.setCaseType("03");
        caseLightModel.setCaseId(id);
        caseLightModel.setDeptId(caseThreeModel.getDeptId());
        caseLightModel.setPplInd("N");
        caseLightModel.setProcInd("N");        
        caseLightModel.setLightInd("N");
        Date date = DateUtil.getDate();
        caseLightModel.setCreateId(caseThreeModel.getCreateId());
        caseLightModel.setUpdateId(caseThreeModel.getCreateId());
        caseLightModel.setCreateDt(date);
        caseLightModel.setUpdateDt(date);
        caseLightMgr.addCaseLight(caseLightModel);
        return caseThreeDAO.getCaseThree(id);
    }

    public CaseThreeModel getCaseThree(int caseThreeId) {
        return caseThreeDAO.getCaseThree(caseThreeId);
    }

    public CaseThreeModel saveCaseThree(CaseThreeModel caseThreeModel) {
        caseThreeDAO.saveCaseThree(caseThreeModel);
        caseLightMgr.updateLightDept("03",caseThreeModel.getCaseThreeId(),caseThreeModel.getDeptId());
        return caseThreeDAO.getCaseThree(caseThreeModel.getCaseThreeId());
    }

    public void deleteCaseThree(int caseThreeId) {
        caseLightMgr.deleteUnuseLight("03",caseThreeId);
        caseThreeDAO.deleteCaseThree(caseThreeId);
    }

    public PaginatedListHelper search(PaginatedListHelper helper, SearchThreeTO searchTO) {
        int count = caseThreeDAO.searchCount(searchTO);
        helper.setFullListSize(count);
        List list = caseThreeDAO.searchList(helper, searchTO);
        helper.setList(list);
        return helper;
    }

    public List getCaseThreeList(SearchThreeTO searchTO) {
        return caseThreeDAO.getCaseThreeList(searchTO);
    }

    public Integer getCaseThreeReportList(SearchThreeTO searchTO) {
        return caseThreeDAO.getCaseThreeReportList(searchTO);
    }
}
